JavaScript オブジェクト操作
[Dict{ A: a, B: b }] -> [Dict{a1: [B], a2: [B], ...}]
code:memo.js
let groups = {name: 'あ', year: 2000},{name: 'あ', year: 2001}
groups.reduce(function(map, group) {
mapgroup.year = (function(m, g) {
if(g.year in m) {
mg.year.push(g.name);
return mg.year
} else {
return g.name
}
})(map, group)
return map
}, {});
// Object { 2000: (2) …, 2001: (1) … }
// 2000: Array "あ", "い"
// 2001: Array "あ"
// <prototype>: Object { … }
#JavaScript